package com.scse.bms.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.scse.bms.domain.RepositoryVO;
import com.scse.bms.entity.RepositoryDO;
import com.scse.bms.mapper.RepositoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Title: RepositoryServiceImpl
 * @Author: 吴赠禹
 * @Date: 2021/3/4 13:18
 * @Version: 1.0
 * @Description: TODO
 */

@Service
@Transactional(rollbackFor = Exception.class)
public class RepositoryServiceImpl extends ServiceImpl<RepositoryMapper, RepositoryDO> implements RepositoryService {

    @Autowired
    private RepositoryMapper repositoryMapper;

    @Override
    public int addBatch(List<RepositoryVO> list) {
        return repositoryMapper.insertBatch(list);
    }

    @Override
    public IPage<RepositoryDO> getAll(Page<?> page) {
        return repositoryMapper.selectAll(page);
    }


    /**
     * 通过审核，加入图书表
     * @param id
     * @return
     */
    @Override
    public int addIntoBook(Integer id) {
        return repositoryMapper.insertIntoBook(id);
    }


    /**
     * 批量清空书库中的图书
     * @param list
     * @return
     */
    @Override
    public int deleteBatch(List<Integer> list) {
        return repositoryMapper.deleteBatch(list);
    }


    /**
     * 批量加入书架
     * @param list
     * @return
     */
    @Override
    public int addIntoBookrackBatch(List<RepositoryDO> list) {
        return repositoryMapper.addToBookrackBatch(list);
    }


}
